package cn.tx.service.impl;

import cn.tx.constant.RedisMessageConstant;
import cn.tx.service.SmsService;
import cn.tx.utils.RandomCode;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/9/4 16:48
 * @Email: 1164763541@qq.com
 */
@Service(interfaceClass = SmsService.class)
@Transactional
public class SmsServiceImpl implements SmsService {
    @Autowired
    private RedisTemplate redisTemplate;
/**
 * @author     :11647
 * @date       ：Created in 2021/9/7  22:31
 * @description：(描述) 预约功能验证码发送
 * @modified By：11647
 * @version:
 */
    @Override
    public void sendRedis(String phone) {
        try {
            String code = RandomCode.genCode();
            System.out.println("验证码：" + code);
            // 存入到redis中
            // 验证码存储到redis中，5分钟后过期
            redisTemplate.boundValueOps(phone + RedisMessageConstant.SENDTYPE_ORDER).set(code, 5, TimeUnit.MINUTES);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
/**
 * @author     :11647
 * @date       ：Created in 2021/9/7  22:32
 * @description：(描述) 登录验证码发送
 * @modified By：11647
 * @version:
 */
    @Override
    public void loginSendRedis(String phone) {
        try {
            System.out.println("手机号码:"+phone);
            String code = RandomCode.genCode();
            System.out.println("验证码：" + code);
            // 存入到redis中
            // 验证码存储到redis中，5分钟后过期
            redisTemplate.boundValueOps(phone + RedisMessageConstant.SENDTYPE_LOGIN).set(code, 5, TimeUnit.MINUTES);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
